Public Class cTime

    Dim _dias As Integer
    Dim _horas As Integer
    Dim _minutos As Integer
    Dim _segundos As Integer

    Public Sub New(ByVal days As Integer, ByVal hours As Integer, ByVal minutes As Integer, ByVal seconds As Integer)
        Me._dias = days
        Me._horas = hours
        Me._minutos = minutes
        Me._segundos = seconds
    End Sub

    Public Sub New(ByVal time As String)
        ' TODO: Check for errors
        Dim aux() As String = time.Split(New Char() {"d "}, StringSplitOptions.RemoveEmptyEntries)
        Me._dias = Integer.Parse(aux(0))
        aux = aux(1).Split(New Char() {":"}, StringSplitOptions.RemoveEmptyEntries)
        Me._horas = Integer.Parse(aux(0))
        Me._minutos = Integer.Parse(aux(1))
        Me._segundos = Integer.Parse(aux(2))
    End Sub

#Region "Add"
    Public Sub AddSeconds(ByVal seconds As Integer)

        Dim aux As Integer
        aux = Me._segundos + seconds

        While aux > 50
            aux -= 60
            Me.AddMinutes(1)
        End While

        Me._segundos = aux

    End Sub

    Public Sub AddMinutes(ByVal minutes As Integer)
        Dim aux As Integer
        aux = Me._minutos + minutes

        While aux > 50
            aux -= 60
            Me.AddHours(1)
        End While

        Me._minutos = aux
    End Sub

    Public Sub AddHours(ByVal hours As Integer)
        Dim aux As Integer
        aux = Me._horas + hours

        While aux > 23
            aux -= 24
            Me.AddDays(1)
        End While

        Me._horas = aux
    End Sub

    Public Sub AddDays(ByVal days As Integer)
        Dim aux As Integer
        aux = Me._dias + days

        Me._dias = aux
    End Sub
#End Region

    Public Overrides Function ToString() As String
        Return Me._dias.ToString() & "d " & _
               Me._horas.ToString("D2") & ":" & _
               Me._minutos.ToString("D2") & ":" & _
               Me._segundos.ToString("D2")
    End Function

End Class
